//
//  SMOptionalViewController.m
//  lishiminOC
//
//  Created by p2p on 16/10/11.
//  Copyright © 2016年 p2p. All rights reserved.
//

#import "SMOptionalViewController.h"
#import "SMOptionalTitleView.h"
#import "SMOptionalCell.h"

@interface SMOptionalViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)SMOptionalTitleView *heardView;

@end

@implementation SMOptionalViewController

#pragma mark - 视图即将显示的方法
- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self setupProperty];
    [self setupUI];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    
}

#pragma mark - 设置界面
- (void)setupUI{
    //添加头部视图
    [self.view addSubview:self.heardView];
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 114, [UIScreen mainScreenWidth], [UIScreen mainScreenHeight]-114 -50) style:UITableViewStylePlain];

    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    tableView.delegate = self;
    tableView.dataSource = self;
    self.tableView = tableView;
    //添加下拉刷新
    [self addRefreshHeaderWithTableView];
    //添加上拉加载
    [self addRefreshFooterWithTableView];
    
    [self.view addSubview:tableView];
}
#pragma mark - 下拉刷新-上拉加载
- (void)addRefreshHeaderWithTableView{
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
}
- (void)headerRefresh{
    NSLog(@"下拉刷新了");
    if (self.tableView.mj_header.isRefreshing) {
        [self.tableView.mj_header endRefreshing];
    }
}
- (void)addRefreshFooterWithTableView{
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
}
- (void)footerRefresh{
    NSLog(@"上拉加载了");
    if (self.tableView.mj_footer.isRefreshing) {
        [self.tableView.mj_footer endRefreshing];
    }
}
#pragma mark - 设置属性及显示
- (void)setupProperty{
    self.title = @"自选";
}
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 15;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SMOptionalCell *cell = [[SMOptionalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    [cell setDataInTheCellWith:@[@"111111111",@"那适宜的尴尬了积分等级佛我案件佛",@"70.33",@"43.09"]];
    cell.selectionStyle                                   = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma mark - UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60.0;
}

#pragma mark - 懒加载
- (SMOptionalTitleView *)heardView{
    if (_heardView == nil) {
        SMOptionalTitleView *heardView = [[SMOptionalTitleView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 50)];
        _heardView = heardView;
        
    }
    return _heardView;
}



@end
